package cn.bluech.lib.utils;

import java.util.Calendar;

/**
 * Description:
 * Date: 2021/3/5.
 */
public class DateUtils {
    // 同一年(如果要使用时间戳换算的话要注意时区,影响年月日)
    public static boolean sameYear(Calendar c1 , Calendar c2) {
        return c1.get(Calendar.YEAR)==c2.get(Calendar.YEAR);
    }
    // 同一月
    public static boolean sameMonth(Calendar c1 , Calendar c2){
        return sameYear(c1,c2) && (c1.get(Calendar.MONTH)==c2.get(Calendar.MONTH));
    }
    // 同一天
    public static boolean sameDay(Calendar c1 , Calendar c2){
        return sameMonth(c1,c2) && (c1.get(Calendar.DAY_OF_MONTH)==c2.get(Calendar.DAY_OF_MONTH));
    }
    // 同一时
    public static boolean sameHour(Calendar c1 , Calendar c2){
        //return sameDay(c1,c2) && (c1.get(Calendar.HOUR_OF_DAY)==c2.get(Calendar.HOUR_OF_DAY));
        long oneHour = 60*60*1000;
        return c1.getTimeInMillis()/oneHour == c2.getTimeInMillis()/oneHour;
    }
    // 同一分
    public static boolean sameMinute(Calendar c1 , Calendar c2){
        //return sameHour(c1,c2) && (c1.get(Calendar.MINUTE)==c2.get(Calendar.MINUTE));
        long oneMinute = 60*1000;
        return c1.getTimeInMillis()/oneMinute == c2.getTimeInMillis()/oneMinute;
    }
    // 同一秒
    public static boolean sameSec(Calendar c1 , Calendar c2){
        return c1.getTimeInMillis()/1000 == c2.getTimeInMillis()/1000;
    }
}
